#!/bin/bash

# 读取.env文件中的APP_NAME变量
if [ -f ".env" ]; then
    APP_NAME=$(grep -E "^APP_NAME=" .env | cut -d '=' -f2- | sed 's/^"\|"$//g')
fi

# 如果没有在.env中找到APP_NAME或为空，则使用默认值"radar"
if [ -z "$APP_NAME" ]; then
    APP_NAME="radar"
fi

# 查找匹配APP_NAME的进程
PROCESSES=$(ps -ef | grep -v grep | grep "$APP_NAME" | awk '{print $2}')

# 如果找到了相关进程，则终止它们
if [ -n "$PROCESSES" ]; then
    echo "Terminating processes: $PROCESSES"
    echo "$PROCESSES" | xargs -t -r kill -9
else
    echo "No processes found matching '$APP_NAME'"
fi